
import { ActionContext, Module} from "vuex"
import { Auth, historyList, vuexStore } from "../type/interface"

const state: Auth = {
  fileName: '',
  historyList: [],
  showHistory: false,
}

const mutations = {
  // 设置文件名参数
  setFileName(state: Auth, val: string){
    state.fileName = val
  },
  // 设置历史记录
  setHistoryList(state: Auth, val: historyList){
    state.historyList.push(val)
  },
  // 查看历史记录
  setHistoryListShow(state: Auth, val: boolean){
    state.showHistory = val
  }
}

const actions = {

}

export const AuthModel: Module<Auth,vuexStore> = {
  state: state,
  mutations,
  actions
}

// 导出模型方法
type name = keyof typeof mutations
type disPatchName = keyof typeof actions

export const authModelUse = ( store:any )=>{
  return {
    commit: (name:name, data?: any)=>{
      store.commit(name, data)
    },
    dispatch:(name: disPatchName, data?:any)=>{
      store.dispatch(name, data)
    },
    state: store.state.AuthModel as Auth
  }
}